// pages/Distribution/Distribution.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menu: [
      {
        title: "分销佣金",
        num: 0.0,
        icon: "../../image/menu_1.png"
      },
    /*  {
        title: "分销订单",
        num: 0.0,
        icon: "../../image/menu_2.png"
      },
      {
        title: "提现明细",
        num: 0.0,
        icon: "../../image/menu_3.png"
      },*/
      {
        title: "下线用户",
        num: 0.0,
        icon: "../../image/xianxian.png",
        nav:"navMember"
      },
      {
        title: "推广二维码",
        icon: "../../image/menu_5.png",
        nav: "getMyCode"
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDeviceOptions();//獲取設備高寬
    getDistribution(this);//获取用户佣金信息
    this.setData({
      userInfo: wx.getStorageSync('userInfo')
    })
   
  },
  getMyCode:function(){
   wx.navigateTo({
     url: '../../pages/myCode/myCode',
   })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: '品德共享酒庄',
      path: '/pages/index/index?id=' + wx.getStorageSync("userid"),
    }
  },
  getDeviceOptions: function () {
    var that=this;
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
  navMember:function(){
    wx.navigateTo({
      url: '../../pages/member/member',
    })
  }
  , getMoney: function () {
    var that=this;
    console.log(wx.getStorageSync("userInfo").nickName);
    wx.request({
      url: app.globalData.allUrl + "/userAction/userDrawings",
      data: {
        merchantId: wx.getStorageSync("userid"),
        typeId:0,
        withdrawPeople: wx.getStorageSync("userInfo").nickName
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        console.log(res);
        if (res.data =="true"){
         wx.showModal({
           title: '提现结果',
           content: '恭喜您提现成功！',
         })
         getDistribution(that)
        }else{
          wx.showModal({
            title: '提现结果',
            content: '提现失败！提现金额少于100无法提现',
          })
        }
  
      }
    })
  }

  ,
  getMoneys:function(){
    var that =this;
    wx.showModal({
      title: '提现',
      content: '是否立即提现？',
      success: function (res) {
        if (res.confirm) {
          that.getMoney();
        } else if (res.cancel) {
        }
      }
    })
  }
})


function getDistribution(that){
  wx.request({
    url: app.globalData.allUrl + "/utilAction/getDistribution",
    data: {
     userID:wx.getStorageSync("userid")
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {    
      console.log(res.data);
      that.data.menu[0].num = res.data.fxBrokerage;
      that.data.menu[1].num = res.data.downline;     
        that.setData({
          userDistribution: res.data, 
          menu: that.data.menu    
        })
      }
  })
   

}